package com.ambitor.ipro.dao;

import java.sql.Connection;

import com.ambitor.grass.sql.dao.SuperDao;
import com.ambitor.grass.sql.dao.impl.SuperDaoImpl;
import com.ambitor.grass.util.data.DataMap;
import com.ambitor.grass.util.data.IData;
import com.ambitor.grass.util.data.IDataset;

public class ArticleDao {

	private SuperDao superDao = null;

	public ArticleDao(Connection conn) {
		superDao = new SuperDaoImpl(conn);
	}

	public int insertArticle(IData article) throws Exception {
		String tableName = "tf_p_article";
		return superDao.insert(tableName, article);
	}
	
	public int saveArticle(IData article) throws Exception {
		String tableName = "tf_p_article";
		return superDao.save(tableName, article);
	}

	public int deleteArticle(IData article) throws Exception {
		String tableName = "tf_p_article";
		return superDao.delete(tableName, article);
	}

	public int[] deleteArticles(IDataset articles) throws Exception {
		String tableName = "tf_p_article";
		return superDao.delete(tableName, articles);
	}

	public IDataset queryAllArticles() throws Exception {
		String tableName = "tf_p_article";
		String columns = "article_id,article_type,article_title,content";
		return superDao.queryList(tableName,columns);
	}

	@SuppressWarnings("unchecked")
	public IData queryArticleByPK(int articleId) throws Exception {
		String tableName = "tf_p_article";
		IData param = new DataMap();
		param.put("article_id", articleId);
		return superDao.queryByPK(tableName, param);
	}
	
	public IData queryArticleByPK(IData data) throws Exception {
		String tableName = "tf_p_article";
		return superDao.queryByPK(tableName, data);
	}

	@SuppressWarnings("unchecked")
	public IDataset queryArticlesByType(String articleType)
			throws Exception {
		String tableName = "tf_p_article";
		IData param = new DataMap();
		param.put("article_type", articleType);
		return superDao.queryList(tableName, param);
	}
}
